<template>
	<div class="publicpageview">
		<div class="publicformview-new">
			<el-form :inline="true" :model="listQuery" size="mini" ref="searchForm">
				<div>
					<el-form-item label="区房屋管理单位：" prop="dname" label-width="130px">
						<el-select :disabled='isluru' v-model="listQuery.dname" @change='areaChange' style="width: 160px" clearable value-key="dname">
							<div v-for="(item,index) in areaList" :key="index">
								<el-option :label="item.dname" :value="item" :key="index"></el-option>
							</div>
						</el-select>
					</el-form-item>
					<el-form-item label="管理部(分中心)：" prop="manageDepartment" label-width="130px">
						<el-select  :disabled='isluru' clearable v-model="listQuery.manageDepartment" @change='HouseChange'
							style="width: 120px">
							<div v-for="(item,index) in HouseList" :key="index">

								<el-option :label="item.aname" :value="item.aid" :key="index"></el-option>
							</div>
						</el-select>
					</el-form-item>
					<el-form-item label="管片代码：" prop="groupNumber" label-width="120px">
						<el-input v-model="listQuery.groupNumber" style="width: 120px"></el-input>
					</el-form-item>
					<el-form-item label="管片名称：" prop="group" label-width="120px">
						<el-input v-model="listQuery.group" style="width: 110px"></el-input>
					</el-form-item>
				</div>
				<el-form-item label="状态：" prop="status" label-width="140px">
					<el-select v-model="listQuery.status" style="width: 160px" clearable>
						<el-option label="正常" value="0" key="0"></el-option>
						<el-option label="禁用" value="-1" key="-1"></el-option>
					</el-select>
				</el-form-item>
				<div style="margin:0 auto;width: 160px">
					<el-button size="mini" type="primary" @click="sumbitCx">查询</el-button>
					<el-button size="mini" @click="resetTop">重置</el-button>
				</div>
			</el-form>
		</div>

		<div class="publitableview">
			<el-button type="primary" size="mini" @click="openQuanxian">权限申请</el-button>
			<el-button v-if="isCompute('管片-录入')" type="primary" size="mini" @click="handleUpdate('',6)">资料录入</el-button>
			<el-button v-if="isCompute('管片-合并')" type="primary" size="mini" @click="handleUpdate('',2)">合并</el-button>
			<el-button v-if="isCompute('管片-批量删除')" type="primary" size="mini" @click="alldelete">批量删除</el-button>
			<el-button type="primary" size="mini" @click="handleout">导出</el-button>
			<el-table max-height='500px' v-loading="listLoading" :data="list" border fit highlight-current-row size="mini"
				ref="multiTable" @selection-change="selectChange">
				<el-table-column type="selection" align="center" prop="phone">
				</el-table-column>

				<el-table-column align="center" label="区房屋管理单位" prop="districename">
				</el-table-column>

				<el-table-column align="center" label="管理部(分中心)" prop="houseadminname">
				</el-table-column>

				<el-table-column align="center" label="管片代码" prop="groupnumber">
				</el-table-column>

				<el-table-column align="center" label="管片名称" prop="groupnew">
				</el-table-column>

				<el-table-column align="center" label="状态" prop="status">
					<template slot-scope="scope">
						{{scope.row.status==0?'正常':'禁用'}}
					</template>
				</el-table-column>

				<el-table-column align="center" label="备注" prop="remake">
				</el-table-column>

				<el-table-column align="center" label="操作" width="280">
					<template slot-scope="scope">
						<el-button v-if="isCompute('管片-拆分')" type="text" size="mini"
							@click="handleUpdate(scope.row.groupno,3,scope.row.groupnew)">拆分</el-button>
						<el-button v-if="isCompute('管片-调整区房屋单位')" type="text" size="mini"
							@click="handleUpdate(scope.row.groupno,4)">调整区房屋管理单位</el-button>
						<el-button v-if="isCompute('管片-修改')" type="text" size="mini"
							@click="handleUpdate(scope.row.groupno,1)">修改</el-button>
						<el-button type="text" size="mini"
							@click="handleUpdate(scope.row.groupno,5,scope.row.groupnew)">关联所</el-button>
						<el-button v-if="isCompute('管片-删除')" type="text" size="mini"
							@click="handleDelete(scope.row.groupno)">删除</el-button>
					</template>
				</el-table-column>
			</el-table>

			<div class="publicpaginationview">
				<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
					:current-page="listQuery.pageNum" background :page-sizes="[10, 20, 50, 100]" :page-size="listQuery.pageSize"
					layout="total, sizes, prev, pager, next, jumper" :total="total" small></el-pagination>
			</div>
		</div>

		<!-- 弹窗部分 -->
		<el-dialog :title="type==1?'管片资料修改':type==2?'管理部(分中心)资料合并':type==3?'管理部(分中心)拆分':type==4?'区房屋管理单位调整':''"
			:visible.sync="dialogVisible" width="50%" :before-close="handleClose">
			<div class="title">{{type==1?'':type==2?'合并后—管理部(分中心)信息':type==3?'被拆分—管理部(分中心)信息':type==4?'':''}}</div>
			<el-form :rules='rules' :model="addQuery" ref="addForm" class="demo-ruleForm" label-position="right"
				label-width="150px">
				<el-form-item label="区房屋管理单位：" prop="districeName">
					<el-select :disabled="type==2" v-model="addQuery.districeName" @change='addAreaChange'>
						<div v-for="(item,index) in areaList" :key="index">
							<el-option :label="item.dname" :value="item.did" :key="index"></el-option>
						</div>
					</el-select>
				</el-form-item>
				<el-form-item label="管理部(分中心)：" prop="aname">
					<el-select :disabled="type==2" v-model="addQuery.aname" @change='addHouseChange'>
						<div v-for="(item,index) in HouseList" :key="index">

							<el-option :label="item.aname" :value="item.aid" :key="index"></el-option>
						</div>
					</el-select>
				</el-form-item>

				<el-form-item label="管片代码：">
					<div style="display:flex">
						<el-input disabled v-model="groupNumberHead"></el-input>
						<el-input maxlength="2" placeholder="请填写两位代码" v-model="groupNumberEnd"></el-input>
					</div>
				</el-form-item>
				<el-form-item label="管片名称：" prop="group">
					<el-input v-model="addQuery.group"></el-input>
				</el-form-item>

				<el-form-item label="状态：" prop="status">
					<el-select v-model="addQuery.status">
						<el-option label="禁用" value="1" key="1"></el-option>
						<el-option label="正常" value="0" key="0"></el-option>
					</el-select>
				</el-form-item>

				<el-form-item label="备注：" prop="remake">
					<el-input v-model="addQuery.remake" type="textarea" :rows="2"></el-input>
				</el-form-item>
			</el-form>

			<div class="saveContent" v-if="type!=2&&type!=3&&type!=5">
				<el-button type="primary" @click="save" size="medium">保 存</el-button>
				<!-- <el-button class="tianjiaButton" v-if="type==1" type="primary" @click="addSuo" size="medium">添加所</el-button> -->
			</div>
			<div class="saveContent" v-if="type==5">
				<el-button type="primary" @click="dialogVisible = false" size="medium">返回</el-button>
			</div>

			<!-- 添加所 -->
			<div v-if="tianjiaVisible">
				<el-dialog title="选择所" :visible.sync="tianjiaVisible" width="40%" :before-close="handleClose" append-to-body
					style="margin-top: 50px;">
					<el-form :inline="true" :model="listQuery" size="mini" ref="searchForm">
						<el-row :gutter="20">
							<el-col :span="14">
								<el-form-item label="所编号：" prop="status">
									<el-select v-model="listQuery.status">
										<el-option label="发布" value="1" key="1"></el-option>
										<el-option label="不发布" value="0" key="0"></el-option>
									</el-select>
								</el-form-item>
							</el-col>
							<el-col :span="6">
								<div>
									<el-button size="mini" type="primary">查询</el-button>
									<el-button size="mini" @click="resetForm('searchForm')">重置</el-button>
								</div>
							</el-col>
						</el-row>
					</el-form>
					<el-table v-loading="listLoading" :data="list" border fit highlight-current-row size="mini">
						<el-table-column type="selection" align="center" prop="phone">
						</el-table-column>

						<el-table-column align="center" label="所编号" prop="userId">
						</el-table-column>

						<el-table-column align="center" label="所在地" prop="userName">
						</el-table-column>

						<el-table-column align="center" label="操作" width="100">
							<template slot-scope="scope">
								<el-button type="text" size="mini" @click="handleDelete(scope.row.id)">删除</el-button>
							</template>
						</el-table-column>
					</el-table>

					<div class="publicpaginationview">
						<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
							:current-page="listQuery.pageNum" background :page-sizes="[10, 20, 50, 100]"
							:page-size="listQuery.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"
							small></el-pagination>
					</div>

					<div class="saveContent">
						<el-button type="primary" @click="tianjiaVisible = false" size="medium">确定</el-button>
					</div>
				</el-dialog>
			</div>

			<!-- 合并 -->
			<div v-if="type==2">
				<div class="title">被合并—管片信息</div>
				<el-table v-loading="listLoading" :data="hebingList" border fit highlight-current-row size="mini">

					<el-table-column align="center" label="区房屋管理单位" prop="districename">
					</el-table-column>

					<el-table-column align="center" label="管理部(分中心)" prop="houseadminname">
					</el-table-column>

					<el-table-column align="center" label="管片代码" prop="groupnumber">
					</el-table-column>

					<!-- 	<el-table-column align="center" label="状态" prop="userId">
					</el-table-column> -->

					<el-table-column align="center" label="操作">
						<template slot-scope="scope">
							<el-button type="text" size="mini" @click="hebingleDelete(scope.row.groupno)">删除</el-button>
						</template>
					</el-table-column>
				</el-table>

				<!-- <div class="saveContent">
					<el-button type="primary" @click="dialogVisible = false" size="medium">添加</el-button>
				</div> -->
				<div class="saveContent">
					<el-button type="primary" @click="hebingGp" size="medium">合并</el-button>
				</div>
			</div>

			<!-- 拆分 -->
			<div v-if="type==3">
				<div class="title" style="display: flex;align-items: center;justify-content: space-between;">
					<div style="width: 60%;text-align: right;">拆分后—管片信息</div>
					<div>
						<el-button type="primary" @click="chaifenAdd" size="medium">添加</el-button>
					</div>
				</div>
				<el-table max-height='400px' v-loading="listLoading" :data="chaifenAddList" border fit highlight-current-row
					size="mini">

					<el-table-column align="center" label="区房屋管理单位" prop="districename">
					</el-table-column>

					<el-table-column align="center" label="管理部(分中心)" prop="houseadminname">
					</el-table-column>

					<el-table-column align="center" label="管片代码" prop="groupnumber">
					</el-table-column>

					<el-table-column align="center" label="操作">
						<template slot-scope="scope">
							<el-button type="text" size="mini" @click="chaifenfenpei(scope.row)">所分配</el-button>
							<!-- <el-button type="text" size="mini" @click="chaifenEdit(scope.row.id,1)">修改</el-button> -->
							<el-button type="text" size="mini" @click="chaifenDelete(scope.row.groupno)">删除</el-button>
						</template>
					</el-table-column>
				</el-table>

				<div class="saveContents" v-if="type==3">
					<el-button type="primary" @click="chaifenSave" size="medium">拆分</el-button>
				</div>
				<!-- 拆分管片分配 -->
				<div v-if="isChaifenguanpian">
					<el-dialog title="关联管片" :visible.sync="isChaifenguanpian" width="30%" :before-close="chaifenguanpianClose"
						append-to-body>
						<el-table v-loading="listLoading" :data="guanpianList" border fit highlight-current-row size="mini"
							ref="chaifenguanpianTable" @selection-change="chaifenguanpianChange">
							<el-table-column type="selection" align="center">
							</el-table-column>

							<el-table-column align="center" label="所编号" prop="blockno">
							</el-table-column>
						</el-table>

						<div class="saveContent">
							<el-button type="primary" @click="caifenguanpianSave" size="medium">保 存</el-button>
						</div>

					</el-dialog>

				</div>
				<!-- 拆分添加部门 -->
				<div v-if="isChaifenAdd">
					<el-dialog title="添加部门" :visible.sync="isChaifenAdd" width="50%" :before-close="chaifenClose" append-to-body>
						<el-form :inline="true" :model="tjQuery" size="mini" ref="searchForm" label-width="150px">
							<el-form-item label="区房屋管理单位：" prop="districeName">
								<el-select v-model="tjQuery.districename" @change='chaifenaddAreaChange' value-key="dname">
									<div v-for="(item,index) in areaList" :key="index">
										<el-option :label="item.dname" :value="item" :key="index"></el-option>
									</div>
								</el-select>
							</el-form-item>
							<el-form-item label="管理部(分中心)：" prop="houseadminname">
								<el-select v-model="tjQuery.houseadminname" @change='chaifenaddHouseChange' value-key="aname">
									<div v-for="(item,index) in HouseList" :key="index">

										<el-option :label="item.aname" :value="item" :key="index"></el-option>
									</div>
								</el-select>
							</el-form-item>

							<el-form-item label="管片代码：">
								<el-input disabled v-model="groupNumberHead"></el-input>
								<el-input maxlength="2" placeholder="请填写两位代码" v-model="groupNumberEnd"></el-input>
							</el-form-item>
							<el-form-item label="管片名称：" prop="group">
								<el-input v-model="tjQuery.group"></el-input>
							</el-form-item>

							<el-form-item label="状态：" prop="status">
								<el-select v-model="tjQuery.status">
									<el-option label="禁用" value="1" key="1"></el-option>
									<el-option label="正常" value="0" key="0"></el-option>
								</el-select>
							</el-form-item>

							<el-form-item label="备注：" prop="remake">
								<el-input v-model="tjQuery.remake" type="textarea" :rows="2"></el-input>
							</el-form-item>
						</el-form>
						<div class="saveContent">
							<el-button type="primary" @click="caifenTjSave" size="medium">保 存</el-button>
						</div>

					</el-dialog>

				</div>

				<div v-if="chaifenVisible">
					<el-dialog title="管片拆分_所分配" :visible.sync="chaifenVisible" width="40%" :before-close="handleClose"
						append-to-body style="margin-top: 50px;">
						<el-form :model="formData" ref="dataForm" class="demo-ruleForm" label-position="right" label-width="150px">
							<el-form-item label="区房屋管理单位：" prop="deptId">
								<el-select :disabled='type!=1&&type!=6&&type!=4' v-model="formData.deptId">
									<el-option label="事业部" value="1" key="1"></el-option>
									<el-option label="生活部" value="0" key="0"></el-option>
								</el-select>
							</el-form-item>

							<el-form-item label="管理部(分中心)：" prop="deptId">
								<el-select :disabled='type!=1&&type!=6&&type!=4' v-model="formData.deptId">
									<el-option label="事业部" value="1" key="1"></el-option>
									<el-option label="生活部" value="0" key="0"></el-option>
								</el-select>
							</el-form-item>

							<el-form-item label="管片代码：" prop="userName">
								<el-input :readonly='type!=1&&type!=6&&type!=4' v-model="formData.userName"></el-input>
							</el-form-item>
							<el-form-item label="管片名称：" prop="phone">
								<el-input :readonly='type!=1&&type!=6&&type!=4' v-model.number="formData.phone"></el-input>
							</el-form-item>

							<el-form-item label="状态：" prop="userStatus">
								<el-select :disabled='type!=1&&type!=6&&type!=4' v-model="formData.userStatus">
									<el-option label="启用" value="1" key="1"></el-option>
									<el-option label="禁用" value="0" key="0"></el-option>
								</el-select>
							</el-form-item>

							<el-form-item label="备注：" prop="remarks">
								<el-input :readonly='type!=1&&type!=6&&type!=4' v-model="formData.remarks" type="textarea"
									:rows="2"></el-input>
							</el-form-item>
						</el-form>

						<div v-if="cfType==2">
							<div class="title2">关联所</div>
							<el-table v-loading="listLoading" :data="list" border fit highlight-current-row size="mini">
								<el-table-column type="selection" align="center" prop="phone">
								</el-table-column>

								<el-table-column align="center" label="所编号" prop="userId">
								</el-table-column>

								<el-table-column align="center" label="所在地" prop="userName">
								</el-table-column>

								<el-table-column align="center" label="操作" width="100">
									<template slot-scope="scope">
										<el-button type="text" size="mini" @click="handleDelete(scope.row.id)">删除</el-button>
									</template>
								</el-table-column>
							</el-table>
							<div class="publicpaginationview">
								<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
									:current-page="listQuery.pageNum" background :page-sizes="[10, 20, 50, 100]"
									:page-size="listQuery.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"
									small></el-pagination>
							</div>
						</div>
						<div class="saveContent" v-if="cfType==1">
							<el-button type="primary" @click="chaifenVisible = false" size="medium">保 存</el-button>
						</div>

					</el-dialog>
				</div>
			</div>

		</el-dialog>

		<!-- 弹窗部分 -->
		<el-dialog title="操作权限申请" :visible.sync="isQuanxian" width="50%" :before-close="handleClose">
			<el-form :model="qxQuery" ref="dataForm" class="demo-ruleForm" label-position="right" label-width="150px">
				<el-form-item label="权限名称：" prop="permission">
					<el-select v-model="qxQuery.permission">
						<el-option label="管片-合并" value="管片-合并"></el-option>
						<el-option label="管片-拆分" value="管片-拆分"></el-option>
						<el-option label="管片-删除" value="管片-删除"></el-option>
						<el-option label="管片-修改" value="管片-修改"></el-option>
						<el-option label="管片-录入" value="管片-录入"></el-option>
						<el-option label="管片-批量删除" value="管片-批量删除"></el-option>
						<el-option label="管片-调整区房屋单位" value="管片-调整区房屋单位"></el-option>
					</el-select>
				</el-form-item>

				<el-form-item label="申请人员：" prop="userName">
					<el-input disabled v-model="qxQuery.userName"></el-input>
				</el-form-item>

				<el-form-item label="生效开始时间：" prop="startTime">
					<el-date-picker v-model="qxQuery.startTime" type="date" placeholder="选择日期时间" align="right">
					</el-date-picker>
				</el-form-item>

				<el-form-item label="生效结束时间：" prop="endTime">
					<el-date-picker v-model="qxQuery.endTime" type="date" placeholder="选择日期时间" align="right">
					</el-date-picker>
				</el-form-item>

				<el-form-item label="申请缘由说明：" prop="remake">
					<el-input v-model="qxQuery.remake" type="textarea" :rows="2"></el-input>
				</el-form-item>
			</el-form>

			<div class="saveContent">
				<el-button type="primary" @click="qxSave" size="medium">保 存</el-button>
			</div>
		</el-dialog>




		<!-- 弹窗部分 -->
		<el-dialog title="管片调整" :visible.sync="xiashuVisible" width="50%" :before-close="handleClose" append-to-body
			style="margin-top: 50px;">
			<div>

				<el-form>
					<el-form-item label="调整后管片：" prop="tzhguanpian" label-width="140px">
						<el-select clearable v-model="tzhguanpian">
							<div v-for="(item,index) in list" :key="index">
								<el-option :label="item.groupnew" :value="item.groupnew" :key="index"></el-option>
							</div>
						</el-select>
					</el-form-item>
				</el-form>
				<el-table max-height='400px' @selection-change="selectChanges" v-loading="listLoading" :data="suolist" border
					fit highlight-current-row size="mini">
					<el-table-column type="selection" align="center">
					</el-table-column>

					<el-table-column align="center" label="管片名称" prop="blockgroup">
					</el-table-column>

					<el-table-column align="center" label="所号" prop="blockno">
					</el-table-column>

					<el-table-column align="center" label="所地址" prop="address">
					</el-table-column>
				</el-table>
				<!-- <div class="publicpaginationview">
					<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
						:current-page="listQuery.pageNum" background :page-sizes="[10, 20, 50, 100]"
						:page-size="listQuery.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"
						small></el-pagination>
				</div> -->
			</div>
			<div class="saveContent">
				<el-button type="primary" @click="tiaozheng" size="medium">调整</el-button>
				<el-button type="primary" @click="fanhui" size="medium">返回</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	import dayjs from 'dayjs'
	import * as XLSX from 'xlsx'
	import {
		blockGroupList,
		getArea,
		getHouseAdmin,
		addBlockGroup,
		updBlockGroup,
		delBlockGroup,
		blockGroupDetails,
		blockGroupMerge,
		blockGroupSplit,
		getBlockByGroup,
		permissionApply,
		delMultipleBlockGroup,
		updAllBlockGroup
	} from '@/api/industry'
	export default {
		name: 'AccommodationManagementGuanpian',

		data() {
			return {
				listQuery: {
					pageNum: 1,
					pageSize: 20,
					houseAdmin: '',
					groupNumber: '',
					group: '',
					areaUnit: '',
					dname: '',
					manageDepartment: '',
					status:'0'
				},
				groupNumberHead: '',
				groupNumberEnd: '',
				total: 0,
				list: [],
				listLoading: false,
				dialogVisible: false,
				chaifenVisible: false,
				tianjiaVisible: false,
				formData: {
					userId: '',
					userName: '',
					phone: '',
					deptId: '',
					roleId: '',
					userStatus: '1',
					remarks: ''
				},
				qxQuery: {
					endTime: '',
					permission: '',
					remake: '',
					startTime: '',
					userName: ''
				},
				type: '',
				cfType: '',
				// 区房屋管理单位
				areaList: [],
				// 根据区获取部门
				HouseList: [],
				addQuery: {
					remake: '',
					group: '',
					groupNumber: '',
					houseAdmin: '',
					status: '',
					did: '',
					aname: '',
					districeName: '',
					HouseAdminName: ''
				},
				rules: {
					districeName: [{
						required: true,
						message: '请选择区房屋管理单位',
						trigger: 'blur'
					}],
					aname: [{
						required: true,
						message: '请输入管理部(分中心)',
						trigger: 'blur'
					}],
					groupNumber: [{
						required: true,
						message: '请输入管片代码',
						trigger: 'blur'
					}],
					group: [{
						required: true,
						message: '请输入管片名称',
						trigger: 'blur'
					}],
					status: [{
						required: true,
						message: '请选择状态',
						trigger: 'blur'
					}],
				},
				tjQuery: {
					remake: '',
					group: '',
					groupnumber: '',
					houseadmin: '',
					status: '',
					did: '',
					aname: '',
					districename: '',
					houseadminname: ''
				},
				GroupNo: '',
				ads: '13',
				hebingList: [],
				// 是否展示拆分添加列表
				isChaifenAdd: false,
				// 拆分添加列表
				chaifenAddList: [],
				// 是否展示拆分管片
				isChaifenguanpian: false,
				// 管片列表
				guanpianList: [],
				// 管片被选择列表
				guanpianSelectList: [],
				newAid: '',
				//拆分结果
				sonGroupList: [],
				allList: [],
				groupnew: '',
				blockid: '',
				isQuanxian: false,
				group: '',
				arrID: [],
				userList: [],
				xiashuVisible: false,
				suolist: [],
				guanpianLists: [],
				tzhguanpian: '',
				isluru:false,
				tzBlockno:[]
			}
		},

		computed: {},

		mounted() {
			if (localStorage.getItem('userHouseAdminId') > 0) {
				this.listQuery.areaUnit = localStorage.getItem('userDID')
				this.listQuery.dname = localStorage.getItem('userDname')
				this.listQuery.manageDepartment = localStorage.getItem('userHouseAdminName')
				this.listQuery.houseAdmin = localStorage.getItem('userHouseAdminId')
				this.isluru = true
			}
			this.blockGroupList()
			this.qxQuery.userName = localStorage.getItem('username')
			this.getArea()
			this.userList = JSON.parse(localStorage.getItem('userList'))
		},

		methods: {
			tiaozheng(){
				if(this.tzBlockno.length>0&&this.tzhguanpian){
					let data = {
						blockno:this.tzBlockno.join(","),
						groupNew:this.tzhguanpian
					}
					updAllBlockGroup(data).then(res=>{
						console.log(res)
						this.$message({
							type: 'success',
							message: '操作成功!'
						})
						this.xiashuVisible = false
						this.tzhguanpian = ''
						this.tzBlockno = []
					})
				}else{
					this.$message({
						type: 'success',
						message: '内容不能为空!'
					})
				}
				
			},
			fanhui(){
				
				this.xiashuVisible = false
				this.tzhguanpian = ''
						this.tzBlockno = []
			},
			isCompute(name) {
				if (this.userList.find((item) => item.permission === name)) {
					return true
				} else {
					return false
				}
			},
			// 权限申请
			openQuanxian() {
				this.isQuanxian = true
			},
			qxSave() {
				let data = this.qxQuery
				data.startTime = data.startTime ?
					dayjs(data.startTime).format('YYYY-MM-DD HH:mm:ss') :
					''
				data.endTime = data.endTime ?
					dayjs(data.endTime).format('YYYY-MM-DD HH:mm:ss') :
					''
					data.type = 0
				permissionApply(data).then((res) => {
					console.log(res)
					this.$message({
						type: 'success',
						message: '操作成功!'
					})
					this.isQuanxian = false
				})
			},
			getArea() {
				getArea().then((res) => {
					console.log(res)
					this.areaList = res.data
				})
			},
			getHouseAdmin(e) {
				getHouseAdmin({
					DID: e
				}).then((res) => {
					this.HouseList = res.data
				})
			},
			// 管片列表
			blockGroupList() {
				let data = {
					group: this.listQuery.group,
					groupNumber: this.listQuery.groupNumber,
					houseAdmin: this.listQuery.houseAdmin,
					pageNum: this.listQuery.pageNum,
					pageSize: this.listQuery.pageSize,
					DID: this.listQuery.areaUnit,
					status:this.listQuery.status
				}
				this.listLoading = true
				blockGroupList(data).then((res) => {
					this.list = res.data.list
					this.total = res.data.total
					console.log(this.list)
					this.listLoading = false
				})
			},
			// 选择区房屋管理
			areaChange(e) {
				if (e) {
					this.listQuery.areaUnit = e.did
					this.listQuery.dname = e.dname
					this.getHouseAdmin(e.did)
				}
				this.listQuery.houseAdmin = ''
			},
			// 根据区获取部门
			HouseChange(e) {
				console.log(e)
				this.listQuery.houseAdmin = e
			},
			
			// 查询
			sumbitCx() {
				// if (this.listQuery.houseAdmin) {
				// 	this.blockGroupList()
				// } else {
				// 	this.$message('请选择管理部');
				// }
				this.blockGroupList()
			},
			// 重置
			resetTop() {
				this.listQuery.group = '',
				this.listQuery.groupNumber = '',
				this.listQuery.pageSize = 20,
				this.listQuery.pageNum = 1
			},
			// 弹窗保存
			save() {
				console.log(this.type)
				if (this.groupNumberEnd) {
					this.$refs.addForm.validate((valid) => {
						if (valid) {
							if (this.type == 6) {
								this.addBlockGroup()
							} else if (this.type == 1) {
								this.updBlockGroup()
							} else if (this.type == 5) {
								this.dialogVisible = false
							} else if (this.type == 4) {
								this.updBlockGroup()
							}
						} else {
							console.log('验证失败！')
							return false
						}
					})
				} else {
					this.$message({
						type: 'success',
						message: '请填写代码'
					})
				}

			},
			// 管片弹窗选择区房屋管理
			addAreaChange(e) {
				console.log(e)
				this.addQuery.did = e
				this.areaList.forEach((item, index) => {
					if (item.did == e) {
						this.addQuery.districeName = item.dname
					}
				})
				this.addQuery.houseAdmin = ''
				this.getHouseAdmin(e)
			},
			// 管片弹窗根据区获取部门
			addHouseChange(e) {
				console.log(e)
				this.addQuery.houseAdmin = e
				this.HouseList.forEach((item, index) => {
					if (item.aid == e) {
						this.addQuery.aname = item.aname
						let did = this.addQuery.did < 10 ? '0' + this.addQuery.did : this.addQuery.did
						let asn = item.asn < 10 ? '0' + item.asn : item.asn
						console.log(did, asn)
						this.groupNumberHead = asn
					}
				})
			},
			// 添加管片
			addBlockGroup() {
				let data = {
					group: this.addQuery.group,
					groupNumber: this.groupNumberHead + this.groupNumberEnd,
					houseAdmin: this.addQuery.houseAdmin,
					remake: this.addQuery.remake,
					status: this.addQuery.status,
					HouseAdminName: this.addQuery.aname,
					districeName: this.addQuery.districeName,
					DID: this.addQuery.did
				}
				addBlockGroup(data).then((res) => {
					this.$message(res.message)
					this.dialogVisible = false
					this.popupreset()
					this.blockGroupList()
				})
			},
			// 修改管片
			updBlockGroup() {
				let status = ''
				if (this.addQuery.status == '正常') {
					status = 0
				} else if (this.addQuery.status == '禁用') {
					status = 1
				} else {
					status = this.addQuery.status
				}
				let data = {
					group: this.addQuery.group,
					groupNumber: this.groupNumberHead + this.groupNumberEnd,
					houseAdmin: this.addQuery.houseAdmin,
					remake: this.addQuery.remake,
					status: status,
					HouseAdminName: this.addQuery.aname,
					districeName: this.addQuery.districeName,
					GroupNo: this.GroupNo,
					DID: this.addQuery.did
				}
				updBlockGroup(data).then((res) => {
					this.$message(res.message)
					this.dialogVisible = false
					this.popupreset()
					this.blockGroupList()
				})
			},
			// 重置弹窗
			popupreset() {
				console.log(31)
				this.addQuery.addQuery = '',
					this.addQuery.groupNumber = '',
					this.addQuery.houseAdmin = '',
					this.addQuery.remake = '',
					this.addQuery.status = '',
					this.GroupNo = '',
					this.addQuery.aname = '',
					this.addQuery.districeName = ''
				this.groupNumberHead = ''
				this.groupNumberEnd = ''
				this.addQuery.group = ''
			},
			// 合并外层选择器
			selectChange(e) {
				console.log(e)
				this.hebingList = e

				let arrID = []
				e.forEach((item, index) => {
					arrID.push(item.groupno)
				})
				this.arrID = arrID
			},
			alldelete() {
				let userList = JSON.parse(localStorage.getItem('userList'))
				if (!userList.find((item) => item.permission === '管片-批量删除')) {
					this.$message({
						type: 'success',
						message: '请申请“管片-批量删除”权限或刷新页面!'
					})
				} else {
					console.log(this.arrID)
					if (this.arrID.length > 0) {
						let data = {
							GroupNo: this.arrID
						}
						delMultipleBlockGroup(data).then((res) => {
							console.log(res)
							this.$message({
								type: 'success',
								message: '操作成功'
							})
							this.blockGroupList()
						})
					} else {
						this.$message({
							type: 'success',
							message: '请选择删除对象!'
						})
					}
				}
			},
			// 合并删除
			hebingleDelete(e) {
				this.hebingList.forEach((item, index) => {
					if (item.groupno == e) {
						this.hebingList.splice(index, 1)
					}
				})
			},
			// 合并管片
			hebingGp() {
				let blockGroup = []
				this.hebingList.forEach((item, index) => {
					blockGroup.push(item.groupnew)
				})
				console.log(blockGroup)
				let data = {
					blockGroup: blockGroup,
					group: this.addQuery.group,
					houseAdmin: this.addQuery.houseAdmin,
					remake: this.addQuery.remake,
					status: this.addQuery.status,
					houseAdminName: this.addQuery.aname,
					districeName: this.addQuery.districeName,
					did: this.addQuery.did,
					groupNumber: this.groupNumberHead + this.groupNumberEnd,
				}
				console.log(data)
				blockGroupMerge(data).then((res) => {
					console.log(res)
					this.$message(res.message)
					this.dialogVisible = false
					this.popupreset()
					this.blockGroupList()
				})
			},
			handleSizeChange(val) {
				this.listQuery.pageNum = 1
				this.listQuery.pageSize = val
				this.blockGroupList()
			},
			handleCurrentChange(val) {
				this.listQuery.pageNum = val
				this.blockGroupList()
			},

			resetForm(val) {
				console.log('1')
				this.$refs[val].resetFields()
			},
			handleUpdate(currentData, type, groupnew) {
				let userList = JSON.parse(localStorage.getItem('userList'))
				if (type == 6) {
					if (!userList.find((item) => item.permission === '管片-录入')) {
						this.$message({
							type: 'success',
							message: '请申请“管片-录入”权限或刷新页面!'
						})
					} else {

						if (localStorage.getItem('userHouseAdminId') > 0) {
							this.addQuery.districeName = localStorage.getItem('userDname')
							this.addQuery.aname = localStorage.getItem('userHouseAdminName')
							this.addQuery.houseAdmin = localStorage.getItem('userHouseAdminId'),
								this.addQuery.did = localStorage.getItem('userDID')
							getHouseAdmin({
								DID: localStorage.getItem('userDID')
							}).then((res) => {
								res.data.forEach((item, index) => {
									if (item.aid == localStorage.getItem('userHouseAdminId')) {
										let did = localStorage.getItem('userDID') < 10 ? '0' + localStorage.getItem('userDID') :
											localStorage.getItem('userDID')
										let asn = item.asn < 10 ? '0' + item.asn : item.asn
										console.log(did, asn)
										this.groupNumberHead = asn

									}
								})
							})

						}
						this.dialogVisible = true
					}
				} else if (type == 2) {
					if (!userList.find((item) => item.permission === '管片-合并')) {
						this.$message({
							type: 'success',
							message: '请申请“管片-合并”权限或刷新页面!'
						})
					} else {
						this.addQuery.districeName = localStorage.getItem('userDname')
						this.addQuery.aname = localStorage.getItem('userHouseAdminName')
						this.addQuery.houseAdmin = localStorage.getItem('userHouseAdminId'),
							this.addQuery.did = localStorage.getItem('userDID')
						getHouseAdmin({
							DID: localStorage.getItem('userDID')
						}).then((res) => {
							res.data.forEach((item, index) => {
								if (item.aid == localStorage.getItem('userHouseAdminId')) {
									let did = localStorage.getItem('userDID') < 10 ? '0' + localStorage.getItem('userDID') :
										localStorage.getItem('userDID')
									let asn = item.asn < 10 ? '0' + item.asn : item.asn
									console.log(did, asn)
									this.groupNumberHead = asn

								}
							})
						})
						this.dialogVisible = true
					}
				} else if (type == 3) {
					if (!userList.find((item) => item.permission === '管片-拆分')) {
						this.$message({
							type: 'success',
							message: '请申请“管片-拆分”权限或刷新页面!'
						})
					} else {
						this.dialogVisible = true
					}
				} else if (type == 1) {
					if (!userList.find((item) => item.permission === '管片-修改')) {
						this.$message({
							type: 'success',
							message: '请申请“管片-修改”权限或刷新页面!'
						})
					} else {
						this.dialogVisible = true
					}
				} else if (type == 4) {
					if (
						!userList.find((item) => item.permission === '管片-调整区房屋单位')
					) {
						this.$message({
							type: 'success',
							message: '请申请“管片-调整区房屋单位”权限或刷新页面!'
						})
					} else {
						this.dialogVisible = true
					}
				} else if (type == 5) {
					let data = {
						group: groupnew
					}
					getBlockByGroup(data).then(res => {
						this.suolist = res.data
					})
					this.xiashuVisible = true
				}

				this.type = type
				//   一定要在打开弹窗前 再赋值 不然resetFiles没用
				this.$nextTick(() => {
					this.GroupNo = currentData
				})
				if (type == 1 || type == 3 || type == 4) {
					let data = {
						groupno: currentData
					}
					blockGroupDetails(data).then((res) => {
						console.log(res);
						(this.addQuery.remake = res.data.remake),
						(this.addQuery.group = res.data.groupnew),
						(this.addQuery.groupNumber = res.data.groupnumber),
						(this.addQuery.houseAdmin = res.data.houseadmin),
						(this.addQuery.districeName = res.data.districename),
						(this.addQuery.aname = res.data.houseadminname),
						(this.addQuery.status = res.data.status == 1 ? '禁用' : '正常'),
						(this.addQuery.did = res.data.did)
						console.log(res.data.groupnumber.slice(0, -2))
						console.log(res.data.groupnumber.substr(-2))

						this.groupNumberHead = res.data.groupnumber.slice(0, -2)
						this.groupNumberEnd = res.data.groupnumber.substr(-2)
					})
				}
			},
			handleDelete(e) {
				let userList = JSON.parse(localStorage.getItem('userList'))
				if (!userList.find((item) => item.permission === '管片-删除')) {
					this.$message({
						type: 'success',
						message: '请申请“管片-删除”权限或刷新页面!'
					})
				} else {
					this.$confirm(
							'此操作将删除该条内容，请确认是否继续操作？',
							'删除提示', {
								confirmButtonText: '确定',
								cancelButtonText: '取消',
								type: 'warning'
							}
						)
						.then(() => {
							let data = {
								GroupNo: e
							}
							delBlockGroup(data).then((res) => {
								this.$message({
									type: 'success',
									message: '删除成功!'
								})
								this.blockGroupList()
							})
						})
						.catch(() => {
							this.$message({
								type: 'info',
								message: '已取消删除'
							})
						})
				}
			},

			// 拆分添加列表展示
			chaifenAdd() {
				this.tjQuery.districename = localStorage.getItem('userDname')
				this.tjQuery.houseadminname = localStorage.getItem('userHouseAdminName')
				this.tjQuery.houseadmin = localStorage.getItem('userHouseAdminId'),
					this.tjQuery.did = localStorage.getItem('userDID')
				getHouseAdmin({
					DID: localStorage.getItem('userDID')
				}).then((res) => {
					res.data.forEach((item, index) => {
						if (item.aid == localStorage.getItem('userHouseAdminId')) {
							let did = localStorage.getItem('userDID') < 10 ? '0' + localStorage.getItem('userDID') :
								localStorage.getItem('userDID')
							let asn = item.asn < 10 ? '0' + item.asn : item.asn
							console.log(did, asn)
							this.groupNumberHead = asn

						}
					})
				})
				this.isChaifenAdd = true
				let data = {
					group: '',
					groupNumber: '',
					houseAdmin: '',
					pageNum: '',
					pageSize: 9999
				}
				blockGroupList(data).then((res) => {
					console.log(res)
					this.allList = res.data.list
				})
			},
			// 拆分添加保存
			caifenTjSave() {

				if (this.groupNumberEnd) {
					let userList = JSON.parse(localStorage.getItem('userList'))
					if (!userList.find((item) => item.permission === '管片-录入')) {
						this.$message({
							type: 'success',
							message: '请申请“管片-录入”权限或刷新页面!'
						})
					} else {
						let data = {
							remake: this.tjQuery.remake,
							group: this.tjQuery.group,
							houseadmin: this.tjQuery.houseadmin,
							status: this.tjQuery.status,
							did: this.tjQuery.did,
							aname: this.tjQuery.aname,
							districename: this.tjQuery.districename,
							houseadminname: this.tjQuery.houseadminname,
							groupnumber: this.groupNumberHead + this.groupNumberEnd,
						}
						this.chaifenAddList.push(data)
						this.isChaifenAdd = false
						console.log(this.chaifenAddList)
					}
				} else {
					this.$message({
						type: 'success',
						message: '请填写代码'
					})
				}

			},
			// 拆分添加选择
			chaifentjChange(e) {
				this.chaifenAddList = e
				console.log(this.chaifenAddList)
			},
			// 关闭拆分
			chaifenClose(done) {
				this.$confirm('确认关闭？')
					.then((_) => {
						done()
					})
					.catch((_) => {})
			},
			//拆分所分配打开
			chaifenfenpei(e) {
				this.isChaifenguanpian = true
				this.group = e.group
				let data = {
					group: this.addQuery.group
				}
				this.listLoading = true
				getBlockByGroup(data).then((res) => {
					this.guanpianList = res.data
					this.listLoading = false
				})
			},
			// 拆分管片分配添加选择
			chaifenguanpianChange(e) {
				this.guanpianSelectList = e
				console.log('33', e)
				let sonGroupList = this.sonGroupList
				let blockno = []
				this.guanpianSelectList.forEach((item, index) => {
					blockno.push(item.blockno)
				})
				this.chaifenAddList.forEach((item, index) => {
					if (this.group == item.group) {
						console.log(this.group, item.group)
						console.log(blockno)
						item.blockno = blockno
					}
				})

				// this.guanpianSelectList = e
				// let sonGroupList = this.sonGroupList
				// let blockno = []
				// this.guanpianSelectList.forEach((item, index) => {
				// 	blockno.push(item.blockid)
				// })
				// if (sonGroupList.length > 0) {
				// 	sonGroupList.forEach((item, index) => {
				// 		if (item.group == this.groupnew) {
				// 			item.blockNo = blockno
				// 			item.group = this.groupnew
				// 		} else {
				// 			sonGroupList.push({
				// 				blockNo: blockno,
				// 				group: this.groupnew
				// 			})
				// 		}
				// 	})
				// } else {
				// 	sonGroupList.push({
				// 		blockNo: blockno,
				// 		group: this.groupnew
				// 	})
				// }
				// this.sonGroupList = sonGroupList
			},
			// 管片拆分弹窗选择区房屋管理
			chaifenaddAreaChange(e) {
				console.log(e)
				this.tjQuery.did = e.did
				this.tjQuery.districename = e.dname
				this.tjQuery.houseAdmin = ''
				this.getHouseAdmin(e.did)
			},
			// 管片拆分弹窗根据区获取部门
			chaifenaddHouseChange(e) {
				console.log(e)
				this.tjQuery.houseadminname = e.aname
				this.tjQuery.houseadmin = e.aid
			},

			// 关闭拆分管片分配页面
			chaifenguanpianClose(done) {
				this.$confirm('确认关闭？')
					.then((_) => {
						this.$refs.chaifenguanpianTable.clearSelection()
						this.sonGroupList = []
						this.chaifenAddList = []
						this.guanpianSelectList = []
						done()
					})
					.catch((_) => {})
			},
			//拆分管片分配保存
			caifenguanpianSave() {
				this.isChaifenguanpian = false
			},
			// 拆分保存
			chaifenSave() {
				console.log(this.chaifenAddList)
				let sonGroupList = []
				this.chaifenAddList.forEach((item, index) => {
					sonGroupList.push({
						did: item.did,
						districename: item.districename,
						group: item.group,
						houseadmin: item.houseadmin,
						houseadminname: item.houseadminname,
						remake: item.remake,
						status: item.status,
						blockNo: item.blockno,
						groupNumber: item.groupNumber,
					})
				})
				let data = {
					sonGroupList: sonGroupList,
					group: this.GroupNo
				}
				blockGroupSplit(data).then((res) => {
					console.log(res)
					this.$message(res.message)
					this.dialogVisible = false
					this.popupreset()
					this.blockGroupList()
					this.sonGroupList = []
					this.chaifenAddList = []
					this.guanpianSelectList = []
				})
			},
			// 部门选择删除
			chaifenDelete(e) {
				this.chaifenAddList.forEach((item, index) => {
					if (item.GroupNo == e) {
						this.chaifenAddList.splice(index, 1)
					}
				})
			},

			// 调整房屋单位
			// 添加所
			addSuo() {
				this.tianjiaVisible = true
			},
			handleClose(done) {
				this.$confirm('确认关闭？')
					.then((_) => {
						done()
					})
					.catch((_) => {})
			},

			handleout() {
				this.$confirm('此操作将导出该条内容，请确认是否继续操作？', '导出提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning'
					})
					.then(() => {
						let data = {
							group: this.listQuery.group,
							groupNumber: this.listQuery.groupNumber,
							houseAdmin: this.listQuery.houseAdmin,
							pageNum: this.listQuery.pageNum,
							pageSize: 99999
						}
						blockGroupList(data).then((res) => {
							let list = res.data.list
							let outList = []
							res.data.list.forEach((item, index) => {
								outList.push({
									区房屋管理单位: item.districename,
									'管理部(分中心)': item.houseadminname,
									管片代码: item.groupnumber,
									管片名称: item.groupnew,
									状态: item.status == 0 ? '正常' : '禁用',
									备注: item.remake
								})
							})
							// 获取表格数据
							const data = outList
							// 转换数据为工作表
							const worksheet = XLSX.utils.json_to_sheet(data)
							// 创建新的工作簿
							const workbook = XLSX.utils.book_new()
							// 将工作表添加到工作簿
							XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1')
							// 导出Excel文件
							XLSX.writeFile(workbook, '管片资料.xlsx')
						})
					})
					.catch(() => {
						this.$message({
							type: 'info',
							message: '已取消导出'
						})
					})
			},

			// 管理调整选择器
			selectChanges(e) {
				console.log(e)
				let tzBlockno = []
				e.forEach((item,index)=>{
					tzBlockno.push(item.blockno)
				})
				this.tzBlockno = tzBlockno
			},
		}
	}
</script>
<style scoped>
	.saveContent {
		width: 100%;
		display: flex;
		justify-content: end;
		margin-top: 20px;
		padding-bottom: 20px;
	}

	.saveContents {
		width: 100%;
		display: flex;
		justify-content: space-around;
		margin-top: 20px;
		padding-bottom: 20px;
	}

	.title {
		color: #008c93;
		text-align: center;
		margin-bottom: 20px;
		font-weight: bold;
	}

	.cfguanpian {
		padding-bottom: 20px;
		color: #008c93;
		margin-bottom: 20px;
		font-weight: bold;
	}

	.title2 {
		color: #008c93;
		margin-bottom: 20px;
		font-weight: bold;
	}

	.tianjiaButton {
		border: 2px solid #008c93;
		background-color: #fff;
		color: #008c93;
	}
</style>